package hot100;

import comment.TreeNode;

/**
 * @Author: wzp
 * @CreateTime: 2024-09-14  10:46
 * @Description: 对称二叉树
 * @Version: 1.0
 */
public class hot_101 {
    public static boolean tf;
    public boolean isSymmetric(TreeNode root) {
        if (root==null){
            return tf;
        }
        tf=true;
        dfs(root.left,root.right);
        return tf;
    }
    public void dfs(TreeNode l,TreeNode r){
        if(l==null&&r!=null){
            tf=false;
            return;
        }
        if(l!=null&&r==null){
            tf=false;
            return;
        }
        if(l==null&&r==null){
            return;
        }
        if(l.val!= r.val){
            tf=false;
            return;
        }
        dfs(l.left,r.right);
        dfs(l.right,r.left);
    }

    public static void main(String[] args) {
//        [2,3,3,4,5,null,4]

        TreeNode root = new TreeNode(2);
        root.left = new TreeNode(3);
        root.right = new TreeNode(3);
        root.left.left = new TreeNode(4);
        root.left.right = new TreeNode(5);
        root.right.right = new TreeNode(4);
        System.out.println(new hot_101().isSymmetric(root));

    }

}
